﻿<script type="text/javascript">




    function ClearFormNonP() {

        $('#txtNonPReportDate').datebox('clear');
        $('#txtNonPAgentWorkID').textbox('clear');
        $('#zambCode').combobox('clear');
        $('#zambNumb').combobox('clear');
        $('#txtNonPID').val('');

        $('#zstationCode').combobox('clear');
        $('#zcenterCode').combobox('clear');

        $('#txtNonPOffDutyKM').numberbox('clear');
        $('#txtNonPOnDutyKM').numberbox('clear');
        $('#txtNonPDayKM').numberbox('clear');
        $('#txtNonPRefuelLitre').numberbox('clear');
        $('#txtNonPOnDutyDipstick').numberbox('clear');
        $('#txtNonPOffDutyDipstick').numberbox('clear');
        $('#txtNonPOilConsumption').numberbox('clear');
        $('#txtNonPRefuelInvoiceNumber').textbox('clear');
        $('#txtRemarkNonP').textbox('clear');
        $('#txtResonbackup4').combobox('clear');


    }

    ///////////////////////////////////////////////////////////////////////////////////////////////////////////
    //初始化

    function EUIcombobox(jqS, o) {
        $.ajax({
            type: "POST",
            async: false,
            url: o.url,
            dataType: "JSON",
            success: function (data1, textStatus, jqXHR) {
                o.data = o.OneOption.concat(data1);
                delete o.url;
                delete o.OneOption;
                $(jqS).combobox(o);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert("获取字典数据失败！可能是已经超时，请重新登录！");
            }
        });
    }

   

    //编辑和新增不同，不需要改变的时候去获取下班路码
    function initcomboNonPEdit() {
        EUIcombobox("#zcenterCode", {
            url: '@Url.Content("~/Medical/GetCenter/")',
            valueField: 'ID',
            textField: 'Name',
            //prompt: '--请选择--',
            //editable: false,
            OneOption: [{
                ID: "",
                Name: "--请选择--"
            }],
            onSelect: function (rec) {
                var urlstation = '@Url.Content("~/Medical/GetStation?code=")' + rec.ID;
                EUIcombobox("#zstationCode", {
                    url: urlstation,
                    valueField: 'ID',
                    textField: 'Name',
                    //prompt: '--请选择--',
                    editable: false,
                    OneOption: [{
                        ID: "",
                        Name: "--请选择--"
                    }]
                });
            }
        });
        //#endregion

        //#region 出车分站 初始化
        EUIcombobox("#zstationCode", {
            url: '@Url.Content("~/Medical/GetStation?code=")',
            valueField: 'ID',
            textField: 'Name',
            editable: false,
            OneOption: [{
                ID: "",
                Name: "--请选择--"
            }],
            onSelect: function (rec) {
                var zz = '@Url.Content("~/CM/CarBasicInfo/getPlateByStationID?stationCode=")' + rec.ID;
                EUIcombobox("#zambCode", {
                    url: zz,
                    valueField: 'AmbulanceCode',
                    textField: 'PlateNumber',
                    editable: false,
                    OneOption: [{
                        AmbulanceCode: "",
                        PlateNumber: "--请选择--"
                    }]
                });
                var zzz = '@Url.Content("~/CM/CarBasicInfo/getPlateByStationID?stationCode=")' + rec.ID;
                EUIcombobox("#zambNumb", {
                    url: zzz,
                    valueField: 'AmbulanceCode',
                    textField: 'CarNumber',
                    editable: false,
                    OneOption: [{
                        AmbulanceCode: "",
                        CarNumber: "--请选择--"
                    }]
                });
            }
            //,
            //onChange: function (newValue, oldValue) {
            //    $("#zambNumb").combobox('clear');
            //    $("#zambCode").combobox('clear');
            //}
        });

        //车辆牌号 初始化
        EUIcombobox("#zambCode", {
            url: '@Url.Content("~/CM/CarBasicInfo/getPlateByStationID?stationCode=")',
            valueField: 'AmbulanceCode',
            textField: 'PlateNumber',
            editable: true,
            OneOption: [{
                AmbulanceCode: "",
                PlateNumber: "--请选择--"
            }]
            ,
            onSelect: function (rec) {

                $("#zambNumb").combobox('setValue', rec.AmbulanceCode);  //根据选择车牌对应的ID ，给车辆编号赋值
                //    getoffdutyNoNP();

            }
        });
        EUIcombobox("#zambNumb", {       //选择车辆编号的联动 初始化
            url: '@Url.Content("~/CM/CarBasicInfo/getCarNumberByID?ID=")',
            valueField: 'AmbulanceCode',
            textField: 'CarNumber',
            editable: true,
            OneOption: [{
                AmbulanceCode: "",
                CarNumber: "--请选择--"
            }]
            ,
            onSelect: function (rec) {

                $("#zambCode").combobox('setValue', rec.AmbulanceCode);  //根据选择车辆编号对应的ID，给车牌号赋值 初始化
            }
        });

     
        var urlstrbackup4 = '@Url.Content("~/CM/CarBasicInfo/getDictionarybyTypeID?TypeID=NonProductR")';  //非生产用车原因 初始化
        $.EUIcombobox("#txtResonbackup4", {
            url: urlstrbackup4,
            valueField: 'ID',
            textField: 'Name',
            editable: false,
            OneOption: [{
                ID: "",
                Name: "--请选择--"
            }]

        });
    }


    function initNonProductFill(rowid) {

        NonProductIFExistReport(rowid);
    }

  

    //通过主表的FillState 来判断是否已填写过   ，是修改还是新增？
    function NonProductIFExistReport(rowid) {
        if (rowid == -1)  //新增
        {
        }
        else {  //编辑
            initcomboNonPEdit();

            $.ajax({
                type: 'POST',
                url: '@Url.Content("~/DD/DriverReport/IFExistReportDate")',
                data:
                    {
                        RowID: rowid
                    },
                dataType: "json",
                success: function (jsData) {
                    //通过主表的FillState 来判断是否已填写过 主表

                   

                        $('#FillNonProductDialog').dialog('open');
                     
                        ClearFormNonP();
                        $('#txtNonPID').val(jsData.drinfo.ID);

                        if (jsData.drinfo.ReportDate != null) {
                            var tempNonPReportDate = $.formatDate(jsData.drinfo.ReportDate);//保险
                            $('#txtNonPReportDate').datebox('setValue', tempNonPReportDate);
                           
                        }
                        $('#txtNonPAgentWorkID').textbox('setValue', jsData.drinfo.AgentWorkID);//
                        $('#zambCode').combobox('setText', jsData.drinfo.AmbulanceNumber);//
                        $('#zambNumb').combobox('setValue', jsData.drinfo.AmbulanceCode);//
                        $('#zstationCode').combobox('setValue', jsData.drinfo.StationCode);//
                        $('#zcenterCode').combobox('setValue', jsData.drinfo.CenterCode);//

                        $('#txtNonPOffDutyKM').numberbox('setValue', jsData.drinfo.OffDutyKM);//
                     
                        $('#txtNonPOnDutyKM').numberbox('setValue', jsData.drinfo.OnDutyKM);//
                        $('#txtNonPDayKM').numberbox('setValue', jsData.drinfo.DayKM);//
                        $('#txtNonPRefuelLitre').numberbox('setValue', jsData.drinfo.RefuelLitre);//
                     
                        $('#txtNonPOnDutyDipstick').numberbox('setValue', jsData.drinfo.OnDutyDipstick);//
                        $('#txtNonPOffDutyDipstick').numberbox('setValue', jsData.drinfo.OffDutyDipstick);//
                        $('#txtNonPOilConsumption').numberbox('setValue', jsData.drinfo.OilConsumption);//
                        $('#txtNonPRefuelInvoiceNumber').textbox('setValue', jsData.drinfo.RefuelInvoiceNumber);//
                        $('#txtRemarkNonP').textbox('setValue', jsData.drinfo.Remark);//
                        $('#txtResonbackup4').combobox('setValue', jsData.drinfo.backup4);//


                        getChargeSumNonP("#txtNonPOffDutyKM");
                        getChargeSum2NonP("#txtNonPOffDutyDipstick");
                        getChargeSum2NonP("#txtNonPRefuelLitre");

                   
                }

            });
        }//进入编辑
    } //success






  

    //路码表 与油尺  改变的小判断
    function getChargeSumNonP(cid) {
        $(cid).numberbox({
            onChange: function (newV, oldV) {
                getChargeTotalNonP();
            }
        });
    }
    //路码表 与油尺改变的判断。
    function getChargeTotalNonP() {
        var a = $('#txtNonPOffDutyKM').numberbox('getValue');
        var b = $('#txtNonPOnDutyKM').numberbox('getValue');
        var KMTotal = Number(a) - Number(b);
        if (KMTotal <= 0) {
            $('#txtNonPDayKM').numberbox('setValue', 0);
        }
        else { $('#txtNonPDayKM').numberbox('setValue', KMTotal); }
    }

    function getChargeSum2NonP(cid) {
        $(cid).numberbox({
            onChange: function (newV, oldV) {
                getChargeTotal2NonP();
            }
        });
    }
    //油尺改变的判断。  上班油尺+加油量-下班油尺 =本班耗油
    function getChargeTotal2NonP() {
        var a = $('#txtNonPOnDutyDipstick').numberbox('getValue');
        var b = $('#txtNonPOffDutyDipstick').numberbox('getValue');
        var add = $('#txtNonPRefuelLitre').numberbox('getValue') ? $('#txtNonPRefuelLitre').numberbox('getValue') : 0;
        var KMTotal1 = Number(a) + Number(add) - Number(b);
        if (KMTotal1 <= 0) {
            $('#txtNonPOilConsumption').numberbox('setValue', 0);
        }
        else { $('#txtNonPOilConsumption').numberbox('setValue', KMTotal1); }
    }


</script>

<div id="FillNonProductDialog" class="easyui-dialog" title="填写日报表" data-options="modal:true,collapsible:false,minimizable:false,maximizable:false,closed:true,resizable:false,iconCls:'icon-custom-cWuZiWeiHu'" style="width: 660px; height: auto; padding: 10px;">
    <form id="formSubmitNonP" method="post">
        <input name="ID" id="txtNonPID" type="hidden">

        <div style="width: 100%; height: auto;">
            <table border="0" style="width:99%;height:auto;">
                <tr>
                    <td align="center" colspan="5">
                        <span style="font-size: large; ">非生产用车工作日报表</span>
                    </td>

                </tr>
                <tr>
                    <td align="center">日报日期:</td>
                    <td><input class="easyui-datebox" style="width: 140px" name="ReportDate" id="txtNonPReportDate"></td>

                    <td align="center">
                        填写人工号：
                    </td>
                    <td>
                        <input class="easyui-textbox" style="width: 130px" name="AgentWorkID" id="txtNonPAgentWorkID" data-options="readonly:true">
                    </td>
               
                    <td align="center">
                    
                     </td>
                </tr>
                <tr>
                    <td valign="top" colspan="3">

                        <div class="easyui-accordion" style="width: 100%; height: auto;">
                            <div title="选择出车车辆" data-options="iconCls:'icon-save'" style="overflow:auto;padding:1px;">
                                <table border="0">
                                    <tr style="height:35px">
                                        <td align="right">分中心：</td>
                                        <td align="left" valign="middle">
                                            <input class="easyui-combobox" style="width: 160px" id="zcenterCode" name="CenterCode">
                                        </td>
                                    </tr>

                                    <tr style="height:35px">
                                        <td align="right">分站：</td>
                                        <td align="left" valign="middle">
                                            <input class="easyui-combobox" style="width: 160px " id="zstationCode" name="StationCode">
                                        </td>
                                    </tr>

                                    <tr style="height:35px">
                                        <td align="right">车牌号码：</td>
                                        <td align="left" valign="middle">
                                            <input class="easyui-combobox" style="width: 160px" id="zambCode">
                                        </td>
                                    </tr>

                                    <tr style="height:35px">
                                        <td align="right">车辆编号：</td>
                                        <td align="left" valign="middle">
                                            <input class="easyui-combobox" style="width: 160px" id="zambNumb" name="AmbulanceCode">
                                        </td>
                                    </tr>
                                    <tr style="height:40px">
                                        <td align="right">
                                            备注：
                                        </td>
                                        <td><input class="easyui-textbox" style="width: 270px;height:70px" name="Remark" id="txtRemarkNonP" data-options="multiline:true"></td>
                                    </tr>
                                    <tr style="height:45px">
                                        <td align="left" colspan="2">
                                            注：此页面用于非生产用车情况下填写工作日报。
                                        </td>

                                    </tr>
                                    <tr>
                                        <td align="left" colspan="2">
                                            当出现非生产用车（送修、送保、送检等）情况的时候填写。
                                        </td>

                                    </tr>
                                </table>
                            </div>
                        </div>
                    </td>
                    <td valign="top" width="270px" colspan="2">
                        <table border="0" style="width:270px">
                            <tr>
                                <td>
                                    <div class="easyui-accordion" style="width: 100%; height:inherit;">
                                        <div title="里程情况" data-options="iconCls:'icon-save'" style="overflow:auto;padding:1px;">
                                            <table id="ReportInfo">
                                                <tr style="height:30px"><td style="color:#0099FF;">路码表</td></tr>
                                                <tr style="height:30px">
                                                    <td>
                                                        下班路码：
                                                    </td>
                                                    <td>
                                                        <input class="easyui-numberbox" style="width: 150px" name="OffDutyKM" id="txtNonPOffDutyKM" data-options="precision:2">
                                                    </td>

                                                </tr>
                                                <tr style="height:30px">
                                                    <td>
                                                        上班路码:
                                                    </td>
                                                    <td>
                                                        <input class="easyui-numberbox" style="width: 150px" name="OnDutyKM" id="txtNonPOnDutyKM" data-options="precision:2">
                                                    </td>

                                                </tr>
                                                <tr style="height:30px">
                                                    <td style="color:red;">
                                                        非生产公里数:
                                                    </td>
                                                    <td>
                                                        <input class="easyui-numberbox" style="width: 150px" name="DayKM" id="txtNonPDayKM" data-options="required:true,precision:2">
                                                    </td>
                                                </tr>
                                                <tr style="height:30px">
                                                    <td style="color:red;">
                                                        非生产原因:
                                                    </td>
                                                    <td>
                                                        <input class="easyui-combobox" style="width: 150px" name="backup4" id="txtResonbackup4" data-options="required:true">
                                                    </td>
                                                </tr>

                                            </table>
                                            <table id="CausePerson">
                                                <tr style="height:30px"><td style="color:#0099FF;">油脂情况</td></tr>
                                                <tr style="height:30px">
                                                    <td>
                                                        本班加油：
                                                    </td>
                                                    <td>
                                                        <input class="easyui-numberbox" style="width: 140px" name="RefuelLitre" id="txtNonPRefuelLitre" data-options="precision:2">公升
                                                    </td>
                                                </tr>
                                                <tr style="height:30px">
                                                    <td>
                                                        加油发票号:
                                                    </td>
                                                    <td>
                                                        <input class="easyui-textbox" style="width: 140px" name="RefuelInvoiceNumber" id="txtNonPRefuelInvoiceNumber">
                                                    </td>

                                                </tr>
                                                <tr style="height:30px">
                                                    <td>
                                                        油尺上班:
                                                    </td>
                                                    <td>
                                                        <input class="easyui-numberbox" style="width: 140px" name="OnDutyDipstick" id="txtNonPOnDutyDipstick" data-options="precision:2">公升
                                                    </td>
                                                </tr>
                                                <tr style="height:30px">
                                                    <td>
                                                        油尺下班:
                                                    </td>
                                                    <td>
                                                        <input class="easyui-numberbox" style="width: 140px" name="OffDutyDipstick" id="txtNonPOffDutyDipstick" data-options="precision:2">公升
                                                    </td>
                                                </tr>
                                                <tr style="height:30px">
                                                    <td style="color:red;">
                                                        非生产耗油:
                                                    </td>
                                                    <td>
                                                        <input class="easyui-numberbox" style="width: 140px" name="OilConsumption" id="txtNonPOilConsumption" data-options="required:true,precision:2">公升
                                                    </td>
                                                </tr>

                                            </table>
                                        </div>
                                    </div>
                                </td>
                            </tr>

                        </table>
                    </td>
                </tr>
            </table>
        </div>
    </form>
</div>
